﻿var grid, cbProgress;

//初始化表格
function InitGrid() {
    var startDate = $('#StartDate').datebox('getValue');
    var endDate = $('#EndDate').datebox('getValue');
    grid = $('#tab_list').datagrid({
        name: 'tbl_data',
        url: '/WarrantyTime/InitJsonResult',
        title: '数据信息',
        queryParams: {
            startDate: startDate,
            endDate: endDate
        },
        //width: 815,
        //height: 530,
        //border : false,
        //fit: false,
        fitColumns: false,
        //nowrap: true,
        rownumbers: true,
        //showFooter: true,
        //loadMsg: '正在加载信息...',
        //frozen: true,
        //sortName: "CODE", //排序设置
        singleSelect: true,
        //idField: 'LOCATIONID',
        columns: [[
        //{ field: 'ck', checkbox: true },
                    { field: 'BEGININT', title: '开始天数', align: 'center', sortable: true },
                    { field: 'ENDINT', title: '结束天数', align: 'center', sortable: true },
                    { field: 'TIMEPROPORTION', title: '临保期比例', align: 'center', sortable: true },
                    { field: 'USERNAME', title: '创建人', align: 'center', sortable: true },
                    { field: 'STATUS', title: '状态', align: 'center', sortable: true, formatter: formatBool },
                    { field: 'CREATEDATE', title: '创建时间', align: 'center', sortable: true }
        ]],
        toolbar: [{
            id: 'btnAdd',
            text: '添加',
            iconCls: 'icon-add',
            handler: function () {
                add();
            }
        }],
        pagination: true,
        pageSize: 20,
        pageNumber: 1,
        pageList: [10, 20, 30, 40, 50],
        rownumbers: true, //行号
        onLoadSuccess: function (data) {
            onRefreshButton();
        },
        onSelect: function (rowIndex, rowData) {
            onRefreshButton();
        },
        onUnselect: function (rowIndex, rowData) {
            onRefreshButton();
        },
        onSortColumn: function (sort, order) {
            grid.datagrid('reload');
        }
    });
    //清空选择
    grid.datagrid('clearSelections');
}
function formatBool(val) {
    if (val != null) {
        if (val == "1") {
            return "启用";
        } else {
            return "禁用";
        }
    }
}


//控制按钮
function onRefreshButton() {
    $('#btnAdd').linkbutton('enable');

}

//增加
function add() {
    $('#dlg').dialog('open').dialog('setTitle', '添加商品临保期设置');
    $("#txtBeginInt").val("");
    $("#txtEndInt").val("");
    $("#txtTimeProportion").val("");
    url = '/WarrantyTime/SaveData';
}

function save() {

    $('#location').form('submit', {
        url: '/WarrantyTime/SaveData',
        success: function (data) {
            eval('data=' + data);
            if (data.success) {
                $('#dlg').dialog('close');
                InitGrid();
            } else {
                $.messager.alert('错误', data.msg, 'error');
            }
        }
    });
}

